from kafka import *

producer_path = '../../trans_file/producer_file/'






def read_file(file_name):
    with open(producer_path+file_name, "rb") as r:
        bytes = r.read()
        print(bytes)

    return bytes


def send_message(bytes):
    producer = KafkaProducer(bootstrap_servers=['master:9092'],
                             max_request_size=1024*1000*2)
    producer.send('testPython',value=bytes)
    producer.flush()
    producer.close()
    print("发送成功！")
    pass


if __name__ == '__main__':
    file_name = 'kafka.jpg'
    bytes = read_file(file_name)
    send_message(bytes)